package com.sxl.ocr.ocronnx.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * description:
 * author: shenxiaolong
 * date: 2021/1/27  15:33
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class R<T> {

    private int code;
    private String message;
    private T data;

    public R(int code) {
        this.code = code;
    }

    public R(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public R(T data) {
        this.data = data;
        this.code = 200;
        this.message = "success";
    }

    public static <T> R<T> success(T result) {
        return success(result, 200);
    }

    public static <T> R<T> success() {
        return new R(200);
    }

    public static <T> R<T> success(T result, int code) {
        return new R(code, "success", result);
    }

    public static <T> R<T> success(int code, String message) {
        return new R(code, message);
    }

    public static <T> R<T> fail(String message) {
        return fail(500, message);
    }

    public static <T> R<T> fail(int code, String message) {
        return new R(code, message);
    }


}
